package main

import (
	"fmt"
)

func main() {
	nums := []int{-3, 4, 3, 90}
	res := TwoSum(nums, 0)
	fmt.Println(res)
}

// 给定一个数组，和一个指定的数字，求出两个数组内两个数的和等于指定数字的索引
// mem 3.4M
// sec 2ms
func TwoSum(nums []int, target int) []int {
	mapData := make(map[int]int, len(nums))
	for index, num := range nums {
		mapKey := target - num
		if _, ok := mapData[mapKey]; ok {
			return []int{mapData[mapKey], index}
		} else {
			mapData[num] = index
		}
	}

	return []int{}
}
